// pages/list/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    school_list:[],
    jtlist:[
      {id:0,school_name:'全部节目'},{ id: 1, school_name: '团体节目' }, { id: 2, school_name: '个人节目' }
    ],
		schoolid:0,
		pro_typeid:0,
    classdata:[],       //筛选数据
    promotion_list:[],
    mask:false
  },
  //获取校区
  getschool(){
    app.get({
      url:'index/program/ScreenSchoolCondition'
    }).then(res=>{
      this.setData({
        school_list:res.data
      })
    })
  },
  //已晋级列表
  getpromotion(v){
    app.get({
      url: 'index/program/ProgramDataList', 
      data: { 
        type: v
      }
    })
    .then(res => {
      console.log(res)
      this.setData({
        promotion_list: res.data
      })
    })    
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.setData({
      indextype: options.type
    })
    if (options.type == 1){
      wx.setNavigationBarTitle({
        title: '已晋级节目',
      })
      that.getpromotion(options.type)
    } else if (options.type == 2){
      that.getpromotion(options.type)
      wx.setNavigationBarTitle({
        title: '待助推节目',
      })
    }else{
      wx.setNavigationBarTitle({
        title: '节目',
      })
      wx.getStorage({
        key: 'searchdata',
        success(res) {
          that.setData({
            promotion_list:res.data
          })
        },
        fail(err) {
          
        }
      })
    }
    console.log(options.type)
    // type=1 已晋级节目  type=2 待助推节目
  },
  navTo: function (e) {
    let index = e.currentTarget.dataset.index;
    let item = this.data.promotion_list[index];
    wx.setStorageSync('show_data', item)
    app.navTo(e.currentTarget.dataset.url)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getschool()
  },
  //显示筛选
  scarch:function(e){
    let that = this;
    that.setData({ 
      mask: true,
      classdata: e.currentTarget.dataset.index == 0 ? that.data.school_list : that.data.jtlist,
			classtype:e.currentTarget.dataset.index
    })
  },
  click:function(e){
    let that = this;
		if(that.data.classtype == 0){
			that.setData({
				schoolid:e.currentTarget.dataset.id
			})
		}else{
			that.setData({
				pro_typeid:e.currentTarget.dataset.id
			})
		}
    app.request({
      url: 'index/program/ProgramDataList',
      method: 'get',
      type: 0,
      data: {
        type: that.data.indextype,
        school: that.data.schoolid,
				pro_type:that.data.pro_typeid
      },
      success: function (res) {
        that.setData({
          promotion_list: res.data
        })
      },
    })
    that.setData({ mask: false })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})